package com.qf.service.impl;

import com.qf.dao.AddressDao;
import com.qf.dao.impl.AddressDaoImpl;
import com.qf.entity.Address;
import com.qf.service.AddressService;
import com.qf.util.DbUtils;

import java.util.List;

/**
 * @Author AzureSky_X
 * @Date 2020/11/18 20:08
 * @Version 1.0
 */
public class AddressServiceImpl implements AddressService {
    private AddressDao dao=new AddressDaoImpl();
    @Override
    public List<Address> getAddressList(Integer uid) {
        List<Address> list=null;
        try {
            DbUtils.begin();
            list=dao.selectAddressesByUid(uid);
            DbUtils.commit();
        } catch (Exception e) {
            DbUtils.rollback();
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public int setDefault(int id, int uid) {
        int result=0;
        try {
            DbUtils.begin();
            //将uid下的所有地址设为普通地址
            dao.updateLevelByUid(uid);
            //将id这个地址设为默认地址
            result=dao.updateLevelById(id);
            DbUtils.commit();
        } catch (Exception e) {
            DbUtils.rollback();
            e.printStackTrace();
        }
        return result;
    }
}
